home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Marlais / Marlais 0.5.9-portable sources / character.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  2.2 KB  |  89 lines  |  [TEXT/ttxt]

  1. /* 
  2.  
  3.    character.c
  4.  
  5.    This software is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This software is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public
  16.    License along with this software; if not, write to the Free
  17.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.    Original copyright notice follows:
  20.  
  21.    Copyright, 1993, Brent Benson.  All Rights Reserved.
  22.    0.4 & 0.5 Revisions Copyright 1994, Joseph N. Wilson.  All Rights Reserved.
  23.  
  24.    Permission to use, copy, and modify this software and its
  25.    documentation is hereby granted only under the following terms and
  26.    conditions.  Both the above copyright notice and this permission
  27.    notice must appear in all copies of the software, derivative works
  28.    or modified version, and both notices must appear in supporting
  29.    documentation.  Users of this software agree to the terms and
  30.    conditions set forth in this notice.
  31.  
  32.  */
  33.  
  34. #include "character.h"
  35.  
  36. #include "number.h"
  37. #include "prim.h"
  38.  
  39. static Object integer_to_character (Object i);
  40. static Object character_to_integer (Object ch);
  41.  
  42. static struct primitive char_prims[] =
  43. {
  44.     {"%integer->character", prim_1, integer_to_character},
  45.     {"%character->integer", prim_1, character_to_integer},
  46. };
  47.  
  48. void
  49. init_char_prims (void)
  50. {
  51.     int num;
  52.  
  53.     num = sizeof (char_prims) / sizeof (struct primitive);
  54.  
  55.     init_prims (num, char_prims);
  56. }
  57.  
  58. #ifndef SMALL_OBJECTS
  59. Object
  60. make_character (char ch)
  61. {
  62.     Object obj;
  63.  
  64.     obj = allocate_object (sizeof (struct object));
  65.  
  66.     TYPE (obj) = Character;
  67.     CHARVAL (obj) = ch;
  68.     return (obj);
  69. }
  70. #else
  71. Object
  72. make_character (char ch)
  73. {
  74.     return (MAKE_CHAR (ch));
  75. }
  76. #endif
  77.  
  78. static Object
  79. integer_to_character (Object i)
  80. {
  81.     return (make_character (INTVAL (i)));
  82. }
  83.  
  84. static Object
  85. character_to_integer (Object ch)
  86. {
  87.     return (make_integer (CHARVAL (ch)));
  88. }
  89.